package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.CompanyPersonCostPageBean
import com.hinnotek.amoeba.bean.old.LaborCostDetailBean
import com.hinnotek.amoeba.repo.PersonRepo
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PersonViewModel @Inject constructor(val repository: PersonRepo) : ViewModel() {

    private val addCompanyPersonCostData = StateLiveData<BaseBean>()
    private val laborCostDetailData = StateLiveData<LaborCostDetailBean>()
    private val companyPersonCostPageData = StateLiveData<MutableList<CompanyPersonCostPageBean>>()


    fun getCompanyPersonCostPage(pageNo:Int,pageSize:Int):StateLiveData<MutableList<CompanyPersonCostPageBean>>{
        viewModelScope.launch {
            repository.getCompanyPersonCostPage(pageNo,pageSize, companyPersonCostPageData)
        }
        return companyPersonCostPageData

    }

    /**
     * app端获取全部成本记录分页接口
     */
    fun getCompanyPersonCostById(companyPersonCostId: Int): StateLiveData<LaborCostDetailBean> {
        viewModelScope.launch {
            repository.getCompanyPersonCostById(companyPersonCostId, laborCostDetailData)
        }
        return laborCostDetailData
    }

    fun addCompanyPersonCost(
        companyPersonCostType: Int,
        orgId: Int,
        orgName: String,
        customerId: Int,
        customerName: String,
        amibaCustomerProjectId: Int,
        projectName: String,
        amibaProjectId: Int,
        provideProjectName: String,
        personMoney: String,
        createUser: String,
        companyPersonJson: String
    ): StateLiveData<BaseBean> {
        viewModelScope.launch {
            repository.addCompanyPersonCost(
                companyPersonCostType,
                orgId,
                orgName,
                customerId,
                customerName,
                amibaCustomerProjectId,
                projectName,
                amibaProjectId,
                provideProjectName,
                personMoney,
                createUser,
                companyPersonJson,
                addCompanyPersonCostData
            )
        }
        return addCompanyPersonCostData
    }

}